<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
		<script type="text/javascript">
			document.write('<script src="../../js/fix.js?rd=?rd=' + Math.random() + '"><\/script>');
		</script>
		<script type="text/javascript">
			script(["../../js/H5+.js"]);
			// link(['../../js/app/common.js']);
			// link(['../../css/app.css']);
			// link(['../../css/mui.min.css',]);
			link(['../../fonts/iconfont/iconfont.css']);
		</script>
		<style type="text/css">
			/*4s*/


			html,
			body {
				background: #eee;
				margin: 0rem;
			}

			.swp_box {
				background: #fff;
				padding: 0.15rem;
				margin-top: 0.1rem;
				padding-top: 0.05rem;
			}

			.swp_box .tip {
				color: #545454;
				font-size: 0.14rem;
				margin-bottom: 0.1rem;
			}

			.swp_box .tip>span {
				border-bottom: 0.01rem solid #EEEEEE;
			}

			.swp_box p {
				border-bottom: 0.01rem solid #EEEEEE;
				padding: 0.05rem 0rem;
				font-size: 0.15rem;
			}

			.swp_box .iconfont {
				color: #47BAFE;
				font-size: 0.18rem
			}

			.swp_box .kehuya {
				list-style: none;
				margin: 0px;
				padding-left: 0.15rem;
			}

			.swp_box .kehuya li {
				display: inline-block;
				/* width: 0.6rem; */
				text-align: center;
				font-size: 0.12rem;
			}

			.swp_box .kehuya li img {
				width: 0.6rem;
				height: 0.6rem;
				border-radius: 50%;
			}

			b {
				color: #000000;
			}

			.swp_box lable:first-of-type {
				margin-left: 0.15rem !important;
			}

			#history {
				margin-top: 0rem;
				padding: 0rem;
				display: none;
				padding-left: 0.15rem;
			}

			.swp_box lable {
				position: relative;
				display: inline-block;
				height: 0.3rem;
				margin: 0rem 0.1rem;
				color: #47BAFE;
				width: 0.7rem;
				text-align: center;
				line-height: 0.3rem;
				border: 1px solid #47BAFE;
				border-radius: 30px;
				font-size: 0.13rem;
			}

			.swp_box lable>input[type="radio"] {
				width: 100%;
				height: 100%;
				opacity: 0;
				left: 0rem;
				position: absolute;
			}

			.timebox {
				color: #47BAFE;
				display: flex;
				padding: 0.1rem 0rem;
				align-items: center;
				margin-bottom: 0.15rem;
				margin-left: 0.15rem;
			}

			.timebox span {
				font-size: 0.16rem;
				border-bottom: 0.01rem solid #77c6f5;
				padding-bottom: 0.03rem;
			}

			.mui-btn-outlined {
				border-radius: 10px;
				border-color: #47BAFE;
				margin-left: 0.2rem;
				height: 0.3rem;
				text-align: center;
				padding: 0px 0.1rem;
				margin-left: 0.1rem;
				color: #47BAFE !important;
			}

			.dizhi {
				margin-left: 0.15rem;
			}

			.dizhi>a {
				font-size: 0.13rem;
				color: #47BAFE;
				margin-left: 0.15rem;
			}

			.dizhi>a:active {
				color: blue;
			}

			.swp_box .jieguo {
				width: 50%;
				margin: 0rem;
				display: inline-block;
				text-align: center;
			}

			.swp_box .radio_active {
				color: #fff;
				background: #47BAFE;
			}

			.swp_box .radio_active>i {
				color: #fff;

			}

			.swp_box #rqDate {
				display: none;
				height: 0.3rem;
				color: #47BAFE;
				font-size: 0.18rem;
				/* font-weight: bold; */
				width: 1.5rem;
				margin-left: 0.15rem;
				text-align: center;
				margin-right: 0.1rem;
				line-height: 0.3rem;
			}

			.sound {
				width: 70% !important;
				text-align: center;
				height: 0.35rem;
				background: #47bafe;
				color: #fff !important;
				width: 0.12rem;
				margin: 0 auto;
				margin-left: 15%;
				margin-bottom: 0.1rem;
				border-radius: 30px;
			}

			.swp_box .sound_text {
				text-align: center;
				color: #999999;
				margin-bottom: 0.1rem;
			}

			.commitBtn {
				background-color: #47bafe;
				color: #fff;
				margin-top: 0.1rem;
				line-height: 0.35rem;
				font-size: 0.18rem;
				border: none;
				width: 90%;
				margin: 0 auto;
				margin-left: 5%;
				margin-bottom: 0.1rem;
			}

			.text {
				width: 80%;
				height: 0.5rem;
				border: #00CCCC 1px solid;
				color: #CCCCCC;
			}

			.recogniz {
				width: 2rem;
				height: 1.5rem;
				padding: 0.12rem;
				margin:  auto;
				font-size: 0.16rem;
				background-color: rgba(0, 0, 0, 0.5);
				border-radius: 16px;
				visibility: hidden;
			}

			.partial {
				font-size: 0.14rem;
				color: #FFFFFF;
				border-radius: 5px;
				padding: 0.05rem 0rem;
			}

			.volume {
				width: 0.1rem;
				height: 0.06rem;
				text-align: center;
				border-style: solid;
				display: none;
				box-sizing: border-box;
				border-width: 1px;
				border-color: #47bafe;
				border-radius: 50%;
				margin-top: 0px;
				background-color: #47bafe;
			}

			.rp {
				width: 100%;
				height: 100%;
				display: none;
				text-align: center;
				position: fixed;
				top: 0;
				background: rgba(0, 0, 0, 0.8);
				z-index: 9999;
				overflow: hidden;
			}

			.aname {
				font-size:0.16rem;
			}

			.ainf {
				font-size: 0.12rem;
			}

			.rtime {
				font-size: 0.22rem;
				color: #FF0000;
			}

			.ptime {
				margin-top: 40%;
				font-size: 0.22rem;
				color: #FFFFFF;
			}

			.rprogress {
				background: url(img/arecord.png) no-repeat center center;
				background-size: 0.32rem 0.32rem;
			}



			.progress {
				width: 90%;
				background-color: #666;
				margin: 0 5%;
				border: 0.01rem solid #222;
				-webkit-border-radius: 5px;
				border-radius: 5px;
			}

			.schedule {
				width: 0.08rem;
				height: 0.08rem;
				margin: 0.01rem 0;
				background-color: #FFCC33;
				-webkit-border-radius: 4px;
				border-radius: 4px;
				-webkit-transition: all 1s linear;
				transition: all 1s linear;
			}

			.stop {
				width: 0.72rem;
				height: 0.72rem;
				background: url(img/astop.png) center center;
				background-size: 0.72rem 0.72rem;
				margin: auto;
				-webkit-border-radius: 72px;
				border-radius: 72px;
			}

			.stop:active {
				-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5) inset;
				box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5) inset;
			}

			#iplay {
				display: block;
				background-image: url(../../fonts/iconfont/audioplay.png);
				background-size: 0.2rem 0.2rem;
				background-position-x: 85%;
				background-position-y: center;
				background-repeat: no-repeat;
				-ms-touch-action: auto;
			}

			.spinner {
				margin: 0 auto;
				height: 0.4rem;
				margin-top: 0.2rem;
				margin-bottom: 0.2rem;
				text-align: center;
			}

			.spinner>div {
				background-color: #fff;
				height: 100%;
				width: 0.04rem;
				display: inline-block;

				-webkit-animation: stretchdelay 1.6s infinite ease-in-out;
				animation: stretchdelay 1.6s infinite ease-in-out;
			}

			.spinner .rect2 {
				-webkit-animation-delay: -1.4s;
				animation-delay: -1.4s;
			}

			.spinner .rect3 {
				-webkit-animation-delay: -1.2s;
				animation-delay: -1.2s;
			}

			.spinner .rect4 {
				-webkit-animation-delay: -1.0s;
				animation-delay: -1.0s;
			}

			.spinner .rect5 {
				-webkit-animation-delay: -0.8s;
				animation-delay: -0.8s;
			}

			@-webkit-keyframes stretchdelay {

				0%,
				40%,
				100% {
					-webkit-transform: scaleY(0.4)
				}

				20% {
					-webkit-transform: scaleY(1.0)
				}
			}

			@keyframes stretchdelay {

				0%,
				40%,
				100% {
					transform: scaleY(0.4);
					-webkit-transform: scaleY(0.4);
				}

				20% {
					transform: scaleY(1.0);
					-webkit-transform: scaleY(1.0);
				}
			}

			.mask_sound {
				width: 70%;
				/* background-color: rgba(71, 186, 254, 0.32); */
			}

			.ditem div {
				padding: 0.05rem 0.05rem;
			}

			.ditem {
				background: #FFFFFF;
				border: 1px solid #EEEEEE;
				margin-bottom: 0.05rem;
				margin-top: 0.05rem;
				border-radius: 5px;

			}

			.ditem .audio_text {
				color: #FFFFFF;
				background: #47BAFE;
				height:0.3rem;
				line-height: 0.3rem;
				padding: 0px 0.05rem !important;
			}
			.clear {
				clear:both
			}
			.wrapp {
				display: none;
				float:left;
				background: red;
				height:0.3rem;
				line-height:1.3rem ;
				text-align:center;
			}
			.autxt_span{
				width: 80%;
				display: inline-block;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				height: 0.3rem;
				line-height: 0.3rem;
			}
			.k-line2 {
				display:inline-block;
				background:#666;
				height:0.1rem;
				width:0.1rem;
				opacity:0;
				border-radius:50%;
				transform:translateX(-3rem);
				background-color:#4b9cdb
			}
			.k-line12-1 {
				animation:k-loadingS 4s infinite;
				animation-delay:.8s
			}
			.k-line12-2 {
				animation:k-loadingS 4s infinite;
				animation-delay:.7s
			}
			.k-line12-3 {
				animation:k-loadingS 4s infinite;
				animation-delay:.6s
			}
			.k-line12-4 {
				animation:k-loadingS 4s infinite;
				animation-delay:.5s
			}
			.k-line12-5 {
				animation:k-loadingS 4s infinite;
				animation-delay:.4s
			}
			.k-line12-6 {
				animation:k-loadingS 4s infinite;
				animation-delay:.3s
			}
			.k-line12-7 {
				animation:k-loadingS 4s infinite;
				animation-delay:.2s
			}
			.k-line12-8 {
				animation:k-loadingS 4s infinite;
				animation-delay:.1s
			}
			@keyframes k-loadingS {
				40% {
				transform:translateX(0);
				opacity:.8
			}
			100% {
				transform:translateX(3rem);
				opacity:0
			}
			}
			#pname{
				max-width: 1.2rem;
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
				height: 0.15rem; 
				line-height: 0.15rem;
				display: block; 
			}
		</style>
	</head>

	<body style="display: none; opacity: 0;">
		<div class="swp_box" style="padding-bottom: 0.05rem;">
			<!-- <div class="tip"><span>张先生升职</span> <i class="iconfont iconicon07" style="color: #000000;font-size: 18px;"></i></div> -->
			<p><span class="iconfont iconkehu"></span> <b>客户</b></p>
			<ul class="kehuya">
				<li style="margin-right:20px;display: none;" id="customerobj">
					<a href="javascript:;" style="display: block; "><img src="../../images/mrtxM.jpg" style="height: 0.65rem;width: 0.65rem;" alt="" id="wphoto"></a>
					<span id="pname" cusid="">张先生</span>
				</li>
				<li style="margin-top: 0.05rem;margin-bottom: 0.05rem; transform: translateY(-3px);">
					<a href="javascript:;" id="insert_customer" style="display: block; transform: translateY(-1px);"><img src="../../fonts/iconfont/insert.png" alt="" style="opacity: 0.3;height: 0.6rem;width: 0.6rem;"></a>
					<span style="height: 0.2rem; line-height: 0.2rem;display: block;color:#999;">选择客户</span>
				</li>
			</ul>
			<p><span class="iconfont iconleixing"></span> <b>类型</b></p>
			<lable class="radio_active radioType" onclick="updateType(this)"><input type="radio" name="hudong_type" checked
				 value="0"> 电话 </lable>
			<lable class="radioType" onclick="updateType(this)"><input type="radio" name="hudong_type" value="1"> 微信</lable>
			<lable class="radioType" onclick="updateType(this)"><input type="radio" name="hudong_type" value="2"> 拜访</lable>
		</div>
		<div class="swp_box" style="margin-top: 0rem;">
			<p><span class="iconfont iconshijian"></span> <b>时间</b></p>
			<lable class="radio_active radioDate" onclick="updateDate(this)"><input type="radio" name="time_type" checked value="0">
				今天 </lable>
			<lable class="radioDate" onclick="updateDate(this)"><input type="radio" name="time_type" value="1"> 昨天</lable>
			<div id="rqDate"></div>
			<button type="button" onclick="pickDate()" class="mui-btn mui-btn-primary mui-btn-outlined" style="border-radius: 30px; font-size: 0.13rem;">选择日期</button>
			<div class="timebox" id="timebox" style="display: none;"><span>选择</span>&nbsp; 一&nbsp; <span>选择</span> </div>

			<p style="margin-top: 0.1rem;"><span class="iconfont icondidian"></span> <b>地点</b></p>
			<!-- <div class="dizhi"> <span id="dizhi">北京市长安区12号</span><a href="javascript:;" onclick="showMaps()">选择地址</a></div> -->
			<div class="dizhi"> <span id="dizhi" style="min-width: 40%;display: inline-block;text-align: center;"><span style="color:#999">未选择地点</span></span><a href="javascript:;" id="xzdizhi"  style="font-size: 0.15rem;" >选择地点</a>	 </div>
		</div>
		<div class="swp_box">
			<p><span class="iconfont iconjieguo1"></span> <b>结果如何</b></p>
			<div class="jieguo ">
				<lable class="radio_active radio_jieguo" onclick="updatejieguo(this)">
					<input type="radio" name="jieguordo" id="" value="1" checked="checked" />
					<i style="font-size: 0.14rem;" class="iconfont iconlike"></i>
					顺利
				</lable>
			</div><div class="jieguo ">
				<lable class="radio_jieguo" onclick="updatejieguo(this)"> <input type="radio" name="jieguordo" id="" value="0" />
					<i style="font-size: 0.14rem;" class="iconfont iconcai"></i>
					不顺利</lable>
			</div>
		</div>

		<div class="swp_box" style="margin-bottom: 0.1rem; position: relative;">
			<p><span class="iconfont iconbiji"></span> <b>笔记</b>

				<span id="sound_text1" class="sound_text" style="float: right;font-size: 0.14rem;" onclick="tab_soundText(1)">切换文字记录</span>
				<span id="sound_text2" class="sound_text" style="display: none;float: right;font-size: 0.14rem;" onclick="tab_soundText(2)">切换语音记录</span>
			</p>
			<div id="done2" style=" visibility:hidden;width:70%;height:1rem;text-align:center; position: absolute; top: -240px;left:15%">
				<div id="recogniz" class="recogniz mask_sound">
					<div style="color: #fff">正在倾听
						<div class="spinner" id="spinner">
							<div class="rect1"></div>
							<div class="rect2"></div>
							<div class="rect3"></div>
							<div class="rect4"></div>
							<div class="rect5"></div>
						</div>
						<img src="../../fonts/iconfont/quxiao.png" style="height:0.4rem;display: none;margin: 0 auto;margin-bottom: 0.2rem;margin-top: 0.2rem;"
						 id="icon_quxiaoimg">
					</div>
					<div id="partial" class="partial">手指上滑，取消录制</div>
					<div id="volume" class="volume"></div>
				</div>
			</div>
			<!-- 		<div id="deleteCL" class="button button-waring" style="float: right;text-align: right; color:#47BAFE ; display: none;" onclick="cleanHistory()">删除重录</div> -->
			<ul id="history" class="dlist" style="text-align:left; list-style: none; padding: 0rem;">
				<li id="empty" class="ditem-empty"></li>
			</ul>
			<div id="donebox">
				<textarea id="result" placeholder="语音内容" style="color: #999;margin-bottom: 0px;padding: 0px 0.15rem;width: 100%;border:none;display: none; "></textarea>
				<button id="done" type="button" style="margin-top: 0.01rem;color: #fff;" class="sound  mui-btn-primary mui-btn-outlined">
					请选择客户后录音</button>
			</div> <!-- <div id="result_box" style="width:100%;text-align:center; margin:0 auto; display: none;border:none"> -->

			<textarea id="result2" placeholder="笔记内容" style="font-size: 0.15rem;min-height: 0.5rem;color: #999;margin-bottom: 0px;padding: 0px 0.15rem;width: 100%;border:none; overflow-y:auto !important;display: none;"></textarea>

			<!-- </div> -->

			<div id="outpos" />
		</div>
		<div id="output"></div>
		<div id="play" class="rp" style="width:100%;left: 0px;">
			<div id="ptime" class="ptime">00:00:00/00:00:00</div><br />
			<div id="progress" class="progress" style="">
				<div id="schedule" class="schedule"></div>
			</div>
			<br />
			<!-- <div class="stop" onclick="stopPlay(),outSet('停止播放！')"></div> -->
		</div>


		</div>

		<!-- //滑动坐标 -->
		<div id="zuobiao" isluyin="false"></div>
		<button type="button" class="mui-btn mui-btn-primary commitBtn" id="commBtn">保存</button>
		<script type="text/javascript">
			mui.init();
			document.getElementById("xzdizhi").addEventListener("tap",function(){
					mui.openWindow({
					url: "map.html",
					id: "map",
					styles: {
						titleNView: {
							autoBackButton: true,
							backgroundcolor: "#47BAFE",
							titleText: "选择地点	",
							titlecolor: "white"
						}
					},
					waiting:{
						autoShow:false
					}
				})
			})
		
			function updateType(elm) {
				let objs = document.getElementsByClassName("radioType");
				for (let i = 0; i < objs.length; i++) {
					objs[i].classList.remove("radio_active");
				}
				elm.classList.add("radio_active");
			}

			function updatejieguo(elm) {
				let objs = document.getElementsByClassName("radio_jieguo");
				for (let i = 0; i < objs.length; i++) {
					objs[i].classList.remove("radio_active");
				}
				elm.classList.add("radio_active");

			}

			function updateDate(elm) {
				let objs = document.getElementsByClassName("radioDate");
				for (let i = 0; i < objs.length; i++) {
					objs[i].classList.remove("radio_active");
				}
				elm.classList.add("radio_active");

			}

			function pickDate() {
				// outSet( "打开系统日期选择框：");
				var dDate = new Date();
				dDate.setFullYear();
				var minDate = new Date();
				minDate.setFullYear(2000, 0, 1);
				var maxDate = new Date();
				maxDate.setFullYear(2030, 11, 31);
				// outLine( "[date] "+dDate );
				// outLine( "[minDate] "+minDate );
				// outLine( "[maxDate] "+maxDate );
				plus.nativeUI.pickDate(function(e) {
					var d = e.date;
					// timeobj.style.display="flex";
					// outLine( "选择的日期："+d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate() );
					pickTime(d);


				}, function(e) {
					// outSet( "未选择日期："+e.message );
				}, {
					title: "请选择日期",
					date: dDate,
					minDate: minDate,
					maxDate: maxDate
				});
			}

			function pickTime(date) {
				// outSet( "打开系统时间选择框：");
				var dTime = new Date();
				dTime.setHours(6, 0);
				// outLine( "[time] "+dTime );
				plus.nativeUI.pickTime(function(e) {
					var d = e.date;
					let rqobj = document.getElementById("rqDate");
					let month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
					let gdate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
					let Hours = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
					let Minutes = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
					rqobj.innerText = date.getFullYear() + "-" + month + "-" + gdate + "  " + Hours + ":" + Minutes;
					let dateobj = document.getElementsByClassName("radioDate");
					for (let i = 0; i < dateobj.length; i++) {
						dateobj[i].style.display = "none";
					}
					rqobj.style.display = "inline-block";

					// outLine( "选择的时间："+d.getHours()+":"+d.getMinutes() );
				}, function(e) {
					// outSet( "取消选择时间！" );
				}, {
					title: "请选择时间",
					is24Hour: true,
					time: dTime
				});
			}

			var gentry = null,
				hl = null,
				le = null;
			var er = null,
				ep = null;
			var bUpdated = false; //用于兼容可能提前注入导致DOM未解析完更新的问题
			var text = '';
			var rs=null;
			document.addEventListener('plusready', function() {
			  let self=plus.webview.currentWebview();
			  if(self.cust_id!=undefined){
				  custId = self.cust_id;
				  name = self.name;
				  img = self.img;
				  document.getElementById("wphoto").src = img;
				  document.getElementById("customerobj").style.display = "inline-block";
				  let pnamobj = document.getElementById("pname");
				  pnamobj.setAttribute("cusid", custId);
				  pnamobj.innerText = name;
				  let done = document.getElementById("done");
				  if(localStorage.getItem("isaudioQX")!="false"){
				  	done.innerHTML = "<i class='iconfont iconyuyin' style='color: #fff;font-size: 0.15rem;'></i>按住记录语音笔记";
				  }
				  initDom();
			  }
					//提前给录音权限授权
				plus.android.requestPermissions(['android.permission.RECORD_AUDIO'], function(e){
						if(e.deniedAlways.length>0){	//权限被永久拒绝
							// 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
							console.log('Always Denied!!! '+e.deniedAlways.toString());
							localStorage.setItem("isaudioQX",false);
							let donse=document.getElementById("done");
							donse.innerHTML="没有手机录音权限";
						}
						if(e.deniedPresent.length>0){	//权限被临时拒绝
							// 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
							console.log('Present Denied!!! '+e.deniedPresent.toString());
							localStorage.setItem("isaudioQX",false);
							let donse=document.getElementById("done");
							donse.innerHTML="没有设备录音权限";

						}
						if(e.granted.length>0){	//权限被允许
							//调用依赖获取录音权限的代码
							localStorage.setItem("isaudioQX",true)
							console.log('Granted!!! '+e.granted.toString());
						}
					}, function(e){
						console.log('Request Permissions error:'+JSON.stringify(e));
					});
				initDom();
				cleanHistory();
				// 获取音频目录对象
				
			
			}, false);

			// DOMContentLoaded事件处理
			document.addEventListener('DOMContentLoaded', function() {
				// 获取DOM元素对象
				hl = document.getElementById('history');
				le = document.getElementById('empty');
				er = document.getElementById('record');
				rt = document.getElementById('rtime');
				ep = document.getElementById('play');
				pt = document.getElementById('ptime');
				pp = document.getElementById('progress')
				ps = document.getElementById('schedule');
			}, false);

			var result = null,
				recogniz = null,
				partial = null,
				volume = null;

			function initDom() {

				result = document.getElementById('result');
				recogniz = document.getElementById('recogniz');
				partial = document.getElementById('partial');
				volume = document.getElementById('volume');
				done = document.getElementById('done');
				// done.addEventListener('touchstart', doStart, false);
				// done.addEventListener('touchend', doEnd, false);
				let pnamobj = document.getElementById("pname");
				let pcuiid = pnamobj.getAttribute("cusid");
				done.disabled = true;
				var isaudioQX=localStorage.getItem("isaudioQX");
				if (pcuiid != "" && isaudioQX!="false") {
					done.disabled = false;
					done.addEventListener('touchstart', startRecord, false);
					done.addEventListener('touchmove', moveRecord, false);
					done.addEventListener('touchend', stopRecord, false);
				}
			}


			function startRecognizeSilent() {
				var options = {
					userInterface: false
				};
				plus.speech.startRecognize(options, function(s) {
					console.log('success: ' + s);
				}, function(e) {
					console.log('error: ' + JSON.stringify(e));
				});
			}

			/* ************* 录音功能 ****************** */
			// DOMContentLoaded事件处理
			document.addEventListener('DOMContentLoaded', function() {
				// 获取DOM元素对象
				hl = document.getElementById('history');
				le = document.getElementById('empty');
				// er = document.getElementById('record');
				// rt = document.getElementById('rtime');
				ep = document.getElementById('play');
				pt = document.getElementById('ptime');
				pp = document.getElementById('progress')
				ps = document.getElementById('schedule');
			}, false);
			// 添加播放项
			function createItem(entry) {
				document.getElementById("zuobiao").setAttribute("isluyin", "true");
				var li = document.createElement('li');
				li.className = 'ditem';
				var times = (stopTimestamp - startTimestamp) / 1000;
				var timestring = times.toString();
				var time3 = timestring.substr(0, timestring.length - 2) + "s";
				plus.nativeUI.showWaiting("语音识别中...");
				li.innerHTML =
					'<div id="audio_text" class="audio_text">识别中...<div class="wrapp" style="width:70%"><div class="load-3"><div class="k-line2 k-line12-1" ></div><div class="k-line2 k-line12-2" ></div><div class="k-line2 k-line12-3" ></div><div class="k-line2 k-line12-4" ></div><div class="k-line2 k-line12-5" ></div><div class="k-line2 k-line12-6" ></div><div class="k-line2 k-line12-7" ></div><div class="k-line2 k-line12-8" ></div></div></div></div> <div><span id="iplay" class="iplay"><font class="aname"></font><font class="ainf"></font><span class="audio_time" id="audio_time" style="float:right;margin-right:0.1rem;color:#999;font-size:0.13rem;">' +
					time3 + '</span></span></div> ';
				li.setAttribute('onclick', 'playAudio(this,1)');
				hl.insertBefore(li, le.nextSibling);
				var audoobj = plus.audio.createPlayer('_doc/audio/' + entry.name);
				// alert(audoobj.getDuration());
				// alert((stopTimestamp - startTimestamp)/1000 );
				// li.querySelector('.aname').innerText = entry.name;
				li.querySelector('.ainf').innerText = '...';
				li.entry = entry;
				updateInformation(li);
				// 设置空项不可见
				le.style.display = 'none';

			}

			// 开始录音
			var r = null,
				t = 0,
				ri = null,
				rt = null;
			var startTimestamp = null;
			var stopTimestamp = null;
			var stopTimer = null;
			var isCheng = false;

			function startRecord() {

				let done = document.getElementById("done");
				done.innerText = "松开结束";
				event.preventDefault(); //阻止浏览器默认行为
				posStart = 0;
				posStart = event.touches[0].pageY;
				if (stopTimer) clearTimeout(stopTimer);

				console.log("start");
				console.log(posStart + '---------开始坐标');
				recogniz.style.visibility = 'visible';
				// outSet('开始录音：');
				// posEnd = 0;

				r = plus.audio.getRecorder();
				startTimestamp = (new Date()).getTime();
				if (r == null) {
					// outLine('录音对象未获取');
					return;
				}
				console.log(JSON.stringify(r));
				var fname = "userid_" + new Date().getTime();
				r.record({
					filename: '_doc/audio/' + fname,
					samplerate: '16000',
				}, function(p) {
					// outLine('录音完成：' + p);
					// mui.toast("录制完成");

					plus.io.resolveLocalFileSystemURL(p, function(entry) {
						if (isCheng != false) {

							createItem(entry);
							doUpload(entry);
							isCheng = false;
						}
						// outLine('读取录音文件错误：' + e.message);
					});
				}, function(e) {
					// outLine('录音失败：' + e.message);
					mui.toast("录制失败");
					isCheng = false;
				});

			}

			function moveRecord() {
				event.preventDefault(); //阻止浏览器默认行为
				posMove = 0;
				let zt = document.getElementById("partial");
				let spinner = document.getElementById("spinner");
				let iconquxiao = document.getElementById("icon_quxiaoimg");
				posMove = event.targetTouches[0].pageY; //获取滑动实时坐标

				if (posStart - posMove > 130) {
					zt.style.background = "hsla(0, 99%, 64%, 0.41)";
					spinner.style.display = "none";
					iconquxiao.style.display = "block";
					zt.innerText = '松开手指，取消录制';

				} else {
					zt.style.background = "none";
					spinner.style.display = "block";
					iconquxiao.style.display = "none";
					zt.innerText = '手指上滑，取消录制';
				}
			}
			// 停止录音
			function stopRecord() {
				let done = document.getElementById("done");
				let zt = document.getElementById("partial");
				let spinner = document.getElementById("spinner");
				let iconquxiao = document.getElementById("icon_quxiaoimg");
				zt.style.background = "none";
				spinner.style.display = "block";
				iconquxiao.style.display = "none";
				zt.innerText = '手指上滑，取消录制';
				done.innerHTML = "<i class='iconfont iconyuyin' style='color: #fff;font-size: 0.12rem;'></i>按住记录语音笔记";
				recogniz.style.visibility = 'hidden';
				event.preventDefault();
				posEnd = 0;
				posEnd = event.changedTouches[0].pageY;
				if (posStart - posEnd < 130) {
					// console.log("录制成功");
					stopTimestamp = (new Date()).getTime();
					if (stopTimestamp - startTimestamp < 1000) {
						mui.toast("录音时间太短!");
						isCheng = false;
					} else {
						// mui.toast("录制完成");
						let done = document.getElementById("done");
						done.style.display = "none";
						document.getElementById("history").style.display = "block";
						// document.getElementById("deleteCL").style.display="block";
						isCheng = true;
					}
					r.stop();
					t = 0;
				} else {
					ri = null;
					r.stop();
					w = null;
					r = null;
					// alert("取消录制");
					isCheng = false;
					console.log("取消录制");
					console.log("Cancel");
				};


			}




			function doUpload(entry) {
				storage.init();
				let pnamobj = document.getElementById("pname");
				let cusid = pnamobj.getAttribute("cusid");
				storageUser = kidstorageuser.getInstance();
				let file = document.getElementById("myfile");
				let len = document.getElementById("audio_time").innerText;

				// $('#myfile .up-file')[0].files="_doc/audio/"+entry.name;
				var task = plus.uploader.createUpload("http://118.25.184.62:8000/cmdb/upload_file/", {
						method: "POST"
					},
					function(upload, status) {
						// alert(JSON.stringify(upload));
						// console.log(entry.file);
						console.log(status);
						// 上传完成
						if (status == 200) {
							var str = upload.responseText;
							str = eval("'" + str + "'");
							str = unescape(str.replace(/\u/g, "u"));
							plus.nativeUI.closeWaiting();
							let data = JSON.parse(str);
							if (data.ERROR_MESSAGE == "语音识别失败!") {
								document.getElementById("audio_text").innerHTML =
										"<span class='autxt_span' >语音识别失败！</span><a href='javascript:;'style='float:right'onclick='deteleAudio()'>删除</a>";
							
							} else {
								document.getElementById("audio_text").innerHTML ="<span class='autxt_span' >"+data.DATASET[0].audio_text +
									"</span><span style='float:right'><a href='javascript:;' style='margin-right:0.1rem' onclick='tab_soundText(1)'>编辑</a><a href='javascript:;'onclick='deteleAudio()'>删除</a></span>";
								document.getElementById("audio_text").setAttribute("record_id", data.DATASET[0].record_id);
								document.getElementById("result2").value=data.DATASET[0].audio_text;
							}
						} else {
							console.log("Upload failed: " + status);
						}
					}
				);
				// let path="1556265364990.amr";
				task.addFile('_doc/audio/' + entry.name, {
					key: "myfile"
				});
				task.addData("sales_id", storageUser.UId + "");
				task.addData("cust_id", cusid + "");
				task.addData("audio_len", len + "");
				// task.addData( "sales_id", storageUser.UId );
				// task.addEventListener( "statechanged", onStateChanged, false );
				task.start();

			}
			// function appendFile(p){
			// 
			// }				
			function deteleAudio() {
				document.getElementById("zuobiao").setAttribute("isluyin", "false");
				event.stopPropagation();
				event.preventDefault();
				let done = document.getElementById("done");
				done.style.display = "block";
				cleanHistory();

			}
			// 清除历史记录
			function cleanHistory() {
				hl.innerHTML = '<li id="empty" class="ditem-empty"></li>';
				le = document.getElementById('empty');
				// 删除音频文件
				// outSet('清空录音历史记录：');
				gentry.removeRecursively(function() {
					// Success

				}, function(e) {

				});
			}
			// 获取录音历史列表

			// 获取录音文件信息
			function updateInformation(li) {
				if (!li || !li.entry) {
					return;
				}
				var entry = li.entry;
				entry.getMetadata(function(metadata) {
					li.querySelector('.ainf').innerText = dateToStr(metadata.modificationTime);
				}, function(e) {
					outLine('获取文件"' + entry.name + '"信息失败：' + e.message);
				});
			}
			// 播放音频文件
			var cot = 1;

			function playAudio(li) {
				if (!li || !li.entry) {
					ouSet('无效的音频文件');
					return;
				}
				// outSet('播放音频文件：' + li.entry.name);
				if (cot == 1) {
					jQuery(".iplay").css("background-image", "url(../../fonts/iconfont/audioplay.png)");
					jQuery(li).find(".iplay").css("background-image", "url(../../fonts/iconfont/audiostop.png)");
					startPlay('_doc/audio/' + li.entry.name);
					cot = 2;
				} else {
					jQuery(".iplay").css("background-image", "url(../../fonts/iconfont/audiostop.png)");
					jQuery(li).find(".iplay").css("background-image", "url(../../fonts/iconfont/audioplay.png)");
					stopPlay();
					cot = 1;
				}
			}
			// 播放文件相关对象
			var p = null,
				pt = null,
				pp = null,
				ps = null,
				pi = null;
			// 开始播放
			function startPlay(url) {
				// ep.style.display = 'block';
				// var L = pp.clientWidth;
				p = plus.audio.createPlayer(url);
				// document.getElementById("iplay").style.backgroundImage="url(../../fonts/iconfont/audiostop.png)";

				p.play(function() {
					// outLine('播放完成！');
					// 播放完成
					jQuery(".iplay").css("background-image", "url(../../fonts/iconfont/audioplay.png)");
					cot = 1;

					pt.innerText = timeToStr(d) + '/' + timeToStr(d);
					ps.style.webkitTransition = 'all 0.3s linear';
					ps.style.width = L + 'px';
					stopPlay();
				}, function(e) {
					outLine('播放音频文件"' + url + '"失败：' + e.message);
				});
				// 获取总时长


			}
			// 停止播放
			function stopPlay() {
				document.getElementById("iplay").style.backgroundImage = "url(../../fonts/iconfont/audioplay.png)";
				pi = null;
				// 操作播放对象
				if (p) {
					p.stop();
					p = null;
				}
			}


			function tab_soundText(type) {
				event.preventDefault();
				event.stopPropagation();
				if (type == 1) {
					document.getElementById("donebox").style.display = "none";
					document.getElementById("done2").style.display = "none";
					let resul2t = document.getElementById("result");
					let resul2t2 = document.getElementById("result2");
					resul2t2.style.display = "block";
					resul2t.style.display = "none";
					document.getElementById("history").style.display = "none";
					document.getElementById("sound_text1").style.display = "none";
					document.getElementById("sound_text2").style.display = "block";
					// document.getElementById("history").style.display="none";

				} else {
					document.getElementById("history").style.display = "block";
					document.getElementById("donebox").style.display = "block";
					document.getElementById("done2").style.display = "block";
					let resul2t = document.getElementById("result");
					let resul2t2 = document.getElementById("result2");
					resul2t2.style.display = "none";
					if (resul2t.value != "") {
						resul2t.style.display = "block";
					}

					document.getElementById("sound_text1").style.display = "block";
					document.getElementById("sound_text2").style.display = "none";
					// document.getElementById("history").style.display="block";

				}

			}
			document.getElementById("insert_customer").addEventListener("tap", function() {
				mui.openWindow({
					url: "insert_customer.html",
					id: "insert_customer",
					styles: {
						titleNView: {
							autoBackButton: true,
							backgroundcolor: "#47BAFE",
							titleText: '选择客户',
							titlecolor: "white",
						}
					},
					show: {
						autoShow: true, //页面loaded事件发生后自动显示，默认为true
						aniShow: 'slide-in-bottom', //页面显示动画，默认为”slide-in-right“；
					},
					waiting: {
						autoShow: false
					}
				})
			});

			function gettime(date) {
				var now = date,
					y = now.getFullYear(),
					m = now.getMonth() + 1,
					d = now.getDate();
				return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 5);
			}
			document.getElementById("commBtn").addEventListener("tap", function() {
				let pnamobj = document.getElementById("pname");
				let cusid = pnamobj.getAttribute("cusid");

				if (cusid == "") {
					mui.toast("您还没有选择客户");
					return;
				}
			
				let memo_type = $("input[name='hudong_type']:checked").val();
				let timetype = $("input[name='time_type']:checked").val();
				let jieguo = $("input[name='jieguordo']:checked").val();

				let memo_date;
				let rqobj = document.getElementById("rqDate");
				let location = document.getElementById("dizhi").innerText;
				let isluyin = document.getElementById("zuobiao").getAttribute("isluyin");
				let record_id;
				if (isluyin == "true") {
					record_id = document.getElementById("audio_text").getAttribute("record_id");
				} else {
					record_id = "";
				}
				let result2=document.getElementById("result2").value;
				if(record_id=="" && result2==""){
					mui.toast("请记录内容");
					return;
					}
				var day1 = new Date();
				day1.setDate(day1.getDate() - 1);

				if (rqobj.innerText != "") {
					memo_date = rqobj.innerText;
				} else {
					if (timetype == 0) {
						memo_date = gettime(new Date());
					} else if (timetype == 1) {
						memo_date = gettime(day1);
					}
				}
				storage.init();
				storageUser = kidstorageuser.getInstance();
				request("/cmdb/save_audio_memo/", {
					cust_id: cusid,
					sales_id: storageUser.UId,
					memo_type: memo_type,
					memo_date: memo_date,
					memo_location: location,
					memo_feedback: jieguo,
					record_id: record_id,
					memo_text: document.getElementById("result2").value
				}, function(ruest) {
				// alert(JSON.stringify(ruest));
					mui.toast("保存成功");
					let webviewde=plus.webview.getWebviewById("customerDetail");
					let webviewde2=plus.webview.getWebviewById("insurance_Art_Detail.html");
					mui.fire(webviewde, "xlsx", {});
					mui.fire(webviewde2, "xlsx", {});
					mui.back();
				})
			});

			document.addEventListener("insertCustomer", function(e) {
				custId = e.detail.cusid;
				name = e.detail.name;
				img = e.detail.img;
				document.getElementById("wphoto").src = img;
				document.getElementById("customerobj").style.display = "inline-block";
				let pnamobj = document.getElementById("pname");
				pnamobj.setAttribute("cusid", custId);
				pnamobj.innerText = name;
				let done = document.getElementById("done");
				if(localStorage.getItem("isaudioQX")!="false"){
					done.innerHTML = "<i class='iconfont iconyuyin' style='color: #fff;font-size: 0.15rem;'></i>按住记录语音笔记";
				}
				initDom();
			});
				
				document.addEventListener("insertAddress", function(e) {
			           document.getElementById("dizhi").innerHTML=e.detail.addressName;
			});
		</script>
	</body>

</html>
